/*
2021-7-11
https://www.acwing.com/problem/content/3761/ 
*/

#include<cstring>
#include<algorithm>
#include<iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cout.tie(NULL);
    int T;
    cin>>T;

    while(T--)
    {
        int h,m;
        cin>>h>>m;
        cout<<24*60-h*60-m<<endl;
    }

    return 0;
}

